package com.amigo.online.provider.video.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.amigo.online.common.param.common.MqTag;
import com.amigo.online.common.param.result.VideoInfo;
import com.amigo.online.provider.video.mapper.VideoMapper;
import com.amigo.online.provider.video.rocketmq.RocketMqUtil;

@Component
public class FindVideoWithoutWatermask {


    @Autowired
    private VideoMapper videoMapper;

    private Logger logger = Logger.getLogger(FindVideoWithoutWatermask.class);

    @Scheduled(cron = "0 0 2 ? * WED")
    public void readdWatermark() {
        List<VideoInfo> failVideoList = videoMapper.getAddWatermaskFailedVideo();
        logger.info("找到" + failVideoList.size() + "个无水印的视频");
        for (VideoInfo video : failVideoList) {

            if (video.getAccount() != null) {
                Map<String, Object> videoMap = new HashMap<>();
                videoMap.put("video", video.getVideo());
                videoMap.put("title", video.getTitle());
                videoMap.put("width", video.getWidth());
                videoMap.put("account", video.getAccount());
                videoMap.put("id", video.getId());
                videoMap.put("userId", video.getUserId());
                if (video.getMusicId() != null) {
                    videoMap.put("musicId", video.getMusicId());
                }
                logger.info("----发送加水印消息----");
                logger.info(videoMap);
                RocketMqUtil.send(MqTag.ROCKETMQ_BEAN_VIDEOADDWATERMARK, videoMap, MqTag.FFMPEG);
            }
        }
    }
}
